import { gcj02towgs84 } from "@/utils/CoordinateConvert/gcj02towgs84";
import Emberbox from "@/utils/mapbox/engine";
import { useEmberboxStore } from "../../store";

export default function addLayers(emberbox: Emberbox, source: any, store: any) {
  let layersource = [];
  for (let k in source) {
    let layer = source[k];
    layer.forEach((item: any) => {
      item.geometry.coordinates = item.geometry.coordinates[0];
      item.geometry.coordinates[0].forEach((sets: any) => {
        let asets = gcj02towgs84(sets);
        sets[0] = asets[0];
        sets[1] = asets[1];
      });
      item.geometry.type = "Polygon";
      item.properties["fill-color"] = item.properties["fill-color"].replace(
        "0x",
        "#"
      );
      item.properties["text-color"] = item.properties["fill-color"].replace(
        "0x",
        "#"
      );
    });

    // layer.label = `F${Number(k)}`;
    // layer.value = `${Number(k) - 1}`;
    // layer.key = `${Number(k) - 1}`;

    layersource.push({
      value: `${Number(k)}`,
      label: `${Number(k)}`,
      data: layer,
    });
  }

  console.log("add layers", layersource);

  // console.log(store);
  store.setLayers([layersource]);

  // emberbox.geojsonManage?.addIndoorJson({
  //   type: "FeatureCollection",
  //   features: layersource[0].data,
  // });
}
